package edu.gmu.messages;

import java.util.ArrayList;
import java.util.List;

public class ListManagerResponse implements edu.gmu.middleware.Message{
public ListManagerResponse() { }
public int namingServiceId;
public EndPoint localhost;
public ListManagerRequest request;
public List<Resource> resources;
public EndPoint next;
public EndPoint prev;

public void marshal(edu.gmu.streams.BlockOutputStream stream) throws java.io.IOException{
    stream.writeInt(namingServiceId);
    this.localhost.marshal(stream);
    request.marshal(stream);
    stream.writeInt( resources.size() );
    for (int i = 0; i < resources.size(); i++)
    {
        Resource resource = resources.get(i);
        resource.marshal(stream);
    }
    
    boolean nextIsnull = (next==null);
    stream.writeBoolean(nextIsnull);
    if( nextIsnull == false )
    {
        next.marshal(stream);
    }
    
    boolean prevIsnull = (prev==null);
    stream.writeBoolean(prevIsnull);
    if( prevIsnull == false )
    {
        prev.marshal(stream);
    };
}

public void unmarshal(edu.gmu.streams.BlockInputStream stream) throws java.io.IOException{
    this.namingServiceId = stream.readInt();
    this.localhost = new EndPoint();
    this.localhost.unmarshal(stream);
    
    request = new ListManagerRequest();
    request.unmarshal(stream);
    
    int rSize = stream.readInt();
    this.resources = new ArrayList<Resource>();
    for (int i = 0; i < rSize; i++)
    {
        Resource resource = new Resource();
        resource.unmarshal(stream);
        this.resources.add(resource);
    }
    
    if( stream.readBoolean() == false )
    {
        this.next = new EndPoint();
        this.next.unmarshal(stream);
    }
    
    if( stream.readBoolean() == false )
    {
        this.prev = new EndPoint();
        this.prev.unmarshal(stream);
    }
}
}
